<script src="js/Calendar.js" type="text/javascript"></script>
<script type="text/javascript" src="js/global/Date_func.js"></script>
<link rel="stylesheet" type="text/css" href="css/order_member.css"/>
<script src="js/select2.js"></script>
<link rel="stylesheet" type="text/css" href="css/select2.css">
<style>
    .report{margin:10px 0; padding:15px; border:1px solid #eee}
    .report span.part{ margin-right:20px;}
    input.time{    background: url("images/rili.png") no-repeat scroll right center #FFFFFF;
        border: 1px solid #7F9DB9;
        height: 20px;
        line-height: 20px;
        width: 150px;}
    .total{ width:100%; text-align:center;}
    input.checkbox{ vertical-align:-2px; margin-right:2px;}
    .btn{ background:#eee; padding:4px 15px; *padding:4px 8px; background:url("images/mc_title.png") no-repeat right top; color:#fff; border:none; cursor:pointer}
    #excel{margin-left:10px;}
</style>
<h3 class="mc_title">
    <?if($_a->checkAuth("orderReport.html")){?>
	<span class="mctit_1 <?=($from=="sale")?"":"notcur"?>">
		<a href="orderReport.html"><span class="mctit_2">已卖出产品报表</span></a>
	</span>
    <?}else if($_SERVER['SCRIPT_URI']== 'http://www.12301.cc/orderReport.html'){
        exit;//没有权限看这个页面的人 (单纯的分销商) 还是可以通过输入网址到这里
    }?>
        <span class="mctit_1 <?=($from=="buy")?"":"notcur"?>">
		<a href="buyOrderReport.html"><span class="mctit_2">已买到产品报表</span></a>
	</span>
    <?
    if($_GET['alli']){
        ?>
        <span class="mctit_1 <?=($from=="alliance")?"":"notcur"?>">
		<a href="allianceOrderReport.html"><span class="mctit_2">已卖出联盟产品报表</span></a>
	</span>
    <?}?>
        <span class="mctit_1 notcur">
		<a href="orderReport_Com.html"><span class="mctit_2">数据罗盘</span></a>
	</span>
</h3>
<form class="report" method="get">
    <input type="hidden" name="proList" value='<?//=$proList?>'/>
    <input type="hidden" name="act" id="act" value=""/>
    <p>
		<span class="part">
            <span class="iPart">
                <label>
                    <!--交易日期：-->
                    <select name="xtimes" id="time_type">
                        <option value="1" <?=$_REQUEST['xtimes']==1?'selected' :''?>>下单时间</option>
                        <option value="2" <?=$_REQUEST['xtimes']==2?'selected' :''?>>预计游玩</option>
                        <option value="3" <?=$_REQUEST['xtimes']==3?'selected' :''?>>完成时间</option>
                    </select>
                </label>
                <input type="text" name="begintime" id="begintime" class="time" value="<?=$btime?>" onFocus="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/>
                <label>至</label>
                <input type="text" name="endtime" id="endtime" class="time" value="<?=$etime?>" onFocus="WdatePicker({startDate:'%y-%M-01 23:59:59',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/>
			</span>
            <a href="javascript:changeDate('today');" class="sDate">今天</a>
			<a href="javascript:changeDate('yesterday');" class="sDate">昨天</a>
			<a href="javascript:changeDate('week');" class="sDate">本周</a>
			<a href="javascript:changeDate('lastweek');" class="sDate">上周</a>
			<a href="javascript:changeDate('month');" class="sDate">本月</a>
			<a href="javascript:changeDate('lastmonth');" class="sDate">上月</a>
		</span>
    </p>
    <p>
        <span class="iPart">
            <select class="condSelect controls" name="tjs" id="condSelect">
                <option <?=$_REQUEST['tjs']=="0"?"selected":""?> value="0">订单号</option>
                <option <?=$_REQUEST['tjs']=="2"?"selected":""?> value="2">取票人姓名</option>
                <option <?=$_REQUEST['tjs']=="3"?"selected":""?> value="3">取票人手机</option>
            </select>
            <input id="condInput" type="text" class="condText controls" value="<?=$_REQUEST['txt']?>" name="txt"/>
        </span>
    </p>  
    <p style="margin:10px 0;">
        <span class="leaderTitle">订单状态：</span>
        <span  class="part" id="part">
            <?$_REQUEST['status']= is_array($_REQUEST['status'])?$_REQUEST['status']:array();?>
            <label class="checkList"><input class="checkbox" type="checkbox" name="status[]" <?=in_array("0|1|2|3|5|6|7",$_REQUEST['status'])?"checked":""?> value="0|1|2|3|5|6|7"/>全部</label>
            <label class="checkList"><input class="checkbox" type="checkbox" name="status[]" <?=in_array("0|6",$_REQUEST['status'])?"checked":""?> value="0|6"/>未使用</label>
            <label class="checkList"> <input class="checkbox" type="checkbox" name="status[]" <?=(in_array("1|7",$_REQUEST['status']) ||$_REQUEST['time_type']==3)?"checked":""?> value="1|7"/>已使用</label>
            <label class="checkList"><input class="checkbox" type="checkbox" name="status[]" <?=(in_array("2",$_REQUEST['status'])&& $_REQUEST['time_type']!=3)?"checked":""?> value="2"/>已过期</label>
            <label class="checkList"><input class="checkbox" type="checkbox" name="status[]" <?=(in_array("3|5",$_REQUEST['status']) && $_REQUEST['time_type']!=3)?"checked":""?> value="3|5"/>已取消</label>
        
        </span>
    </p>
    <p>
        <span class="leaderTitle"> 支付状态：</span>
        <select name="pays" class="selectBox">
            <option value="" >不限</option>
            <option value="1" <?=($_REQUEST['pays']=="1")?"selected":""?>>已支付</option>
            <option value="2" <?=($_REQUEST['pays']=="2")?"selected":""?>>未支付</option>
            <option value="0" <?=($_REQUEST['pays']=="0")?"selected":""?>>现场支付</option>
        </select>
        <span  class="part">
            <span class="methTitle">统计方式：</span>
            <select name="by" class="selectBox">
                <option value="">统计方式</option>
                <option value="lid" <?=($_REQUEST['by']=="lid")?"selected":""?>>按景区统计</option>
                <option value="tid" <?=($_REQUEST['by']=="tid")?"selected":""?>>按门票统计</option>
            <?if($from=="sale"){?>
                <option value="mid" <?=($_REQUEST['by']=="mid")?"selected":""?>>按分销商统计</option>
            <?}else{?>
                <option value="aid" <?=($_REQUEST['by']=="aid")?"selected":""?>>按供应商统计</option>
            <?}?>
            </select>
        </span>
    </p>
    <p style="margin:10px 0;">
		<span  class="part">
            <span class="leaderTitle">景点：</span>
            <select name="landid" id="land">
                <option value="">--选择--</option>
                <?foreach($land as $k => $v):?>
                    <option value="<?=$k?>" <?=($_REQUEST['landid']==$k)?"selected":""?>><?=$v?></option>
                <?endforeach;?>
            </select>
            <script>
                $("#land").select2({
                    placeholder: "Select a State",
                    allowClear: true
                });
                $("#s2id_land").css('width','362px');
            </script>
        </span>
    </p>
    <p>
		<span  class="part">
            <span class="leaderTitle">门票：</span>
            <select name="ticket" id="ticket">
                <option value="">--选择--</option>
                <?
                if(isset($_REQUEST['landid']) && !empty($_REQUEST['landid'])){
                    $sql='SELECT id,title FROM uu_jq_ticket WHERE landid='.($_REQUEST['landid']+0);//
                    $GLOBALS['le']->query($sql);
                    $tickes = array();
                    while($row=$GLOBALS['le']->fetch_assoc()){
                        $tickes[]=$row;
                    }
                    if(count($tickes)){
                        $html = '';
                        foreach($tickes as $v){

                            $title= $v['title'];
                            $vs=$v['id'].'_'.$title;
                            if(isset($_REQUEST['ticket']) && !empty($_REQUEST['ticket']) && $_REQUEST['ticket']==$vs){
                                $html.="<option value='{$vs}' selected='selected'>{$title}</option>";
                            }else{
                                $html.="<option value='{$vs}'>{$title}</option>";
                            }
                        }
                        echo $html;
                    }
                }
                ?>
            </select>
        </span>
    </p>
    <p >
        <p class="colorGray">
        <?if(isset($DistorsNames) && count($DistorsNames)>0):?>
        <?if($from == 'sale'):?>
            <span  class="part">
            <?=$dTypeName?>：<?=GetHtmlSelect($DistorsNames, 'fid', $fid, array('k'=>0,'v'=>'--分销商--'))?>
            </span>
            <input class="checkbox ml20" type="checkbox" name="tbms" <?=($_GET['tbms']==1)?"checked":""?> value="1"/><label>淘宝码商</label>
        <?else:?>
        <span  class="part">
            <?=$dTypeName?>：<?=GetHtmlSelect($DistorsNames, 'aid', $aid, array('k'=>0,'v'=>'--供应商--'))?>
        </span>
        <input class="checkbox" type="checkbox" name="tbms" <?=($_GET['tbms']==1)?"checked":""?> value="1"/><label>淘宝码商</label>
       </p>
       <p>
            <div  class="part" style="margin-top:5px; margin-left: 20px;">
                <span class="leaderTitle">分销商套票售卖：</span>
                <?=GetHtmlSelect($FenstorsNames, 'fenid', $fenid, array('k'=>0,'v'=>'--分销商--'))?>
            </div>
        </p>
    <?endif;?>
    <?endif;?>
    </p>
    <p>
        <span  class="part">
            <span class="leaderTitle">报表类型:</span>
            <select name="order_type" class="order_type">
                <option value="3" <?=($_GET['order_type']==3)?" selected":""?>>不含取消和退票的报表</option>
                <option value="1" <?=($_GET['order_type']==1)?" selected":""?>>销售总表</option>
                <option value="2" <?=($_GET['order_type']==2)?" selected":""?>>取消和退票统计报表</option>
            </select>
            <span class="colorGray">说明: 销售总表 = 不含取消和退票的报表 + 取消和退票统计报表</span>
        </span>
    </p>
    <p>
        <span class="leaderTitle"></span>
        <input type="submit" class="btn" value="查 询"/>
        <?if(!$access['yd']):?>
            <input type="button" id="excel" class="btn" value="导 出"/>
        <?endif;?>
    </p>
    
</form>
<div class="rank">
    <div class="rankcon">
        <table class="ranktab" id="ranktab">
            <thead id="rankhd">
            <th>序号</th>
            <th style="text-align:left" class="tL"><?=$titleT[$by]?></th>
            <th><span style="position:relative; left:-40px;" class="sort" onclick="sortTable('offmain',2, true ,this);"><?=($_GET['order_type']!=2)?"订单数量":"取消订单的时间"?></span></th>
            <th><span class="sort" onclick="sortTable('offmain',3, true ,this);">门票数量</span></th>
            <th><span class="sort" onclick="sortTable('offmain',4, true ,this);">金额</span></th>
            <?if(!$access['yd']):?>
                <th><span class="sort" onclick="sortTable('offmain',5, true ,this);">余额支付</span></th>
            <?endif;?>
            <th><span class="sort" onclick="sortTable('offmain',6, true ,this);">支付宝</span></th>
            <th><span class="sort" onclick="sortTable('offmain',7, true ,this);">授信支付</span></th>
            <th><span class="sort" onclick="sortTable('offmain',8, true ,this);">产品自销</span></th>
            <th><span class="sort" onclick="sortTable('offmain',9, true ,this);">现场支付</span></th>
            <th><span class="sort" onclick="sortTable('offmain',10, true ,this);">微信</span></th>
            <th><span class="sort" onclick="sortTable('offmain',11, true ,this);">银联</span></th>
            <th><span class="sort" onclick="sortTable('offmain',12, true ,this);">环迅</span></th>
            <?if(/*$_SESSION['sid']==4 &&*/ $from=='sale'){//杜丽美要的利润?>
                <th><span class="sort" onclick="sortTable('offmain',10, true ,this);">利润</span></th>
            <?}?>
            </thead>
            <tbody id="offmain">
            <?
            if(count($r)){
                foreach($r as $lid=>$row){
                    if(empty($row['order']) && $_GET['order_type']!=2) continue;
                    $totals['order']+=$row['order'];
                    $totals['tnum']+=$row['tnum'];
                    $totals['money']+=$row['money']/100;
                    $totals['pmode0']+=$row['pmode0']/100;
                    $totals['pmode1']+=$row['pmode1']/100;
                    $totals['pmode2']+=$row['pmode2']/100;
                    $totals['pmode3']+=$row['pmode3']/100;
                    $totals['pmode4']+=$row['pmode4']/100;
                    $totals['pmode5']+=$row['pmode5']/100;
                    $totals['pmode7']+=$row['pmode7']/100;
                    $totals['pmode8']+=$row['pmode8']/100;
                    if(/*$_SESSION['sid']==4 &&*/ $from=='sale'){//杜丽美要的利润
                        $totals['lirun']+=$row['lirun']/100;
                    }
                    ?>
                    <tr>
                        <td><?=++$n?></td>
                        <td class="tL"><?=$row['title']?></td>
                    <? if($_GET['order_type']!=2){?>
                        <td>
                            <?if(/*$_SERVER['SCRIPT_URI']=='http://www.12301.cc/buyOrderReport.html' && */$_POST['fenid']){?>
                                <a style="color:#0794e6; font-weight:bold; padding:0 3px;" href="#"><?=$row['order']?></a>
                                <input class="ordernumInp" type="hidden" value="<?=$row['ordernumInp']?>"/>
                                <a class="queryonumBtn" style="display:inline-block; width:80px; color:#0794e6;" href="#">查看订单号</a>
                            <?}else{?>
                                <a style="color:#3E3E3E;margin-left:-80px" href="#"><?=$row['order']?></a>
                            <?}?>
                            <style type="text/css">
                                .onumSelect{ display:none; width:80px; height:23px;}
                            </style>
                            <select class="onumSelect">
                                <option value="1">0325415</option>
                                <option value="2">0325415</option>
                                <option value="3">0325415</option>
                                <option value="4">0325415</option>
                                <option value="5">0325415</option>
                                <option value="6">0325415</option>
                                <select>
                        </td>
                        <?}else{?>
                        <td style="position:relative; left:-40px;"><?=$row['time']?></td>
                        <?}?>
                        <td><?=$row['tnum']?></td>
                        <td><?=$row['money']/100?></td>
                        <?if(!$access['yd']):?>
                            <td><?=$row['pmode0']/100?></td>
                        <?endif;?>
                        <td><?=$row['pmode1']/100?></td>
                        <td><?=$row['pmode2']/100?></td>
                        <td><?=$row['pmode3']/100?></td>
                        <td><?=$row['pmode4']/100?></td>
                        <td><?=$row['pmode5']/100?></td>
                        <td><?=$row['pmode7']/100?></td>
                        <td><?=$row['pmode8']/100?></td>
                        <?if(/*$_SESSION['sid']==4 &&*/ $from=='sale'){//杜丽美要的利润?>
                            <td><?=$row['lirun']/100?></td>
                        <?}?>

                    </tr>
                <?}}?>
            </tbody>
            <tfoot>
            <?if(count($r)>0){?>
                <tr>
                    <td colspan="2">总计：</td>
                    <?if($_GET['order_type']!=2){?>
                    <td><a <?if(!$_POST['fenid']){?>style="color:#3E3E3E;margin-left:-80px"<?}else{?>style="color:#3E3E3E;margin-left:-82px"<?}?>/><?=$totals['order']?></td>
                    <?}else{?>
                    <td><?=$totals['time']?></td>
                    <?}?>
                    <td><?=$totals['tnum']?></td>
                    <td><?=$totals['money']?></td>
                    <?if(!$access['yd']):?>
                        <td><?=$totals['pmode0']?></td>
                    <?endif;?>
                    <td><?=$totals['pmode1']?></td>
                    <td><?=$totals['pmode2']?></td>
                    <td><?=$totals['pmode3']?></td>
                    <td><?=$totals['pmode4']?></td>
                    <td><?=$totals['pmode5']?></td>
                    <td><?=$totals['pmode7']?></td>
                    <td><?=$totals['pmode8']?></td>
                    <?if(/*$_SESSION['sid']==4 &&*/ $from=='sale'){//杜丽美要的利润?>
                        <td><?=$totals['lirun']?></td>
                    <?}?>
                </tr>
            <?}else{?>
                <tr>
                    <td align="left" colspan="9">&nbsp;&nbsp;&nbsp;交易日期无销售订单！</td>
                </tr>
            <?}?>
            </tfoot>
        </table>
    </div>
</div>

<script src="js/jsorder.js"></script>
<script src="http://www.12301.cc/js/WdatePicker.js"></script>
<script>
    $("#time").change(function(){
        Date_func.selectDate($(this).val(),$("#begintime").get(0),$("#endtime").get(0));
    });
    $("input.btn").click(function(){
        var btime=$("#begintime").val();
        var etime=$("#endtime").val();
        btime=btime.split("-");
        etime=etime.split("-");
        month=(etime[0]-btime[0])*12+(etime[1]-btime[1]);
        if(month>3){
            //alert("交易日期时间间隔不能超过三个月");
            //return false;
        }
    });
    // 获取门票
    $("#land").change(function(){

        landid=$(this).val();
        if(landid==''){
            _options = '<option value="">--选择--</option>';
            $("#ticket").html(_options);
            return;
        }
        $.ajax({
            uri:window.location.href,
            data:"landid="+landid,
            beforeSend:function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("request_type","getTicket");
            },
            success: function(data){
                data = JSON.parse(data);
                if(data.s=='success'){
                    _options = '<option value="">--选择--</option>';
                    for(var i in data.content){
                        _options+='<option value="'+data.content[i].id+'_'+data.content[i].title+'">'+data.content[i].title+'</option>';
                    }
                    $("#ticket").html(_options);

                }
            }
        });
    });

    $("#excel").click(function(){
//        $("#act").val("orderReportExcel");
//        $("form.report").submit();
//        $("#act").val("");

        $("#ranktab tbody tr").each(function(){
            var currentTarget = $(this);
            $(this).children('td').each(function(i){
                if(i==2){
                    var num = $(this).children('a').text();
                    $(this).html(num);
                }
            })
        })
        tableToExcel('ranktab', 'W3C Example Table')
    });
    var tableToExcel = (function() {
        var uri = 'data:application/vnd.ms-excel;base64,'
            , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
            , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
            , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
        return function(table, name) {
            if (!table.nodeType) table = document.getElementById(table)
            var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
            window.location.href = uri + base64(format(template, ctx))
        }
    })()
    function changeDate(date){
        // lastweek颠倒了
     if(date=='lastweek'){
            Date_func.selectDate(date,$("#begintime").get(0),$("#endtime").get(0));
        }
     if(date!='lastweek'){
        Date_func.selectDate(date,$("#begintime").get(0),$("#endtime").get(0));
     }
    }

    <?if($_SESSION['sid']==24705){ //pzp 九天要的直接查看这个页面不要登录
     //还要把头部和导航栏的链接给去掉
    ?>
    $(function() {
        $('.header').remove();
        $('.subnav').empty();
    });
    <?}?>

    <?/*?>

   if($("select[name='xtimes']").val()==3){
       xtime_3();
   }
   //选择完成时间时 下面的订单状态选项不可以用
   $("select[name='xtimes']").change(function(){
       if($(this).val()==3){
           xtime_3();
       }else{
           $("span#part input").attr('disabled',false);
           $("span#part select").attr('disabled',false);
       }
   })

   function xtime_3(){
       $("span#part input").attr('disabled','disabled').attr('checked',false);
       $("span#part select").attr('disabled','disabled');
       $("span#part select option").each(function(){
           $(this).attr('selected','selected')
           return false;
       })
   }
   <?*/?>
</script>